import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx;




class FourthPage extends StatefulWidget {
  FourthPage({Key key}) : super(key: key);

  @override
  _FourthPageState createState() => _FourthPageState();
}

class _FourthPageState extends State<FourthPage> {
  String _result = "无";

   @override
  void initState() { 
    super.initState();
    debugPrint("四");
    initWX();
    fluwx.responseFromAuth.listen((data) {
      print('xxx');
      setState(() {
        _result = "${data.errCode}";
        print(_result);
      });
      print(data);
    });
  }
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Center(
         child:   RaisedButton(
            child: Text("微信登录"),
            onPressed: (){
              loginWX();
            },
            color: Colors.blue[200],
            splashColor:Colors.yellow[100],
          ),
       ),
    );
  }

  void initWX() async{
    await fluwx.registerWxApi(
        appId:"wx2bceaea27129163e",
        doOnAndroid: true,
        doOnIOS: true,
        // enableMTA: false
        );
    var result = await fluwx.isWeChatInstalled();
    print("is installed $result");
  }

  ///微信登录
  void loginWX() {
    print("微信登录：：：");
    fluwx
        .sendWeChatAuth(scope: "snsapi_userinfo", state: "wechat_sdk_demo_test")
        .then((data) {
      setState(() {
        print("拉取微信用户信息：" + data.toString());
      });
    }).catchError((e) {
      print('weChatLogin  e  $e');
    });
  }


}